package cn.lxh.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import cn.lxh.pojo.domain.DriverPoint;
import cn.lxh.mapper.DriverPointMapper;
import cn.lxh.pojo.dto.DriverPointDto;
import cn.lxh.service.IDriverPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lxh Create Time: 2024/1/11 15:08
 */
@Service
public class DriverPointServiceImpl implements IDriverPointService {

    @Autowired
    private DriverPointMapper driverPointMapper;

    /**
     * 新增司机坐标
     * @param point
     */
    @Override
    public void save(DriverPoint point) {
        driverPointMapper.save(point);
    }

    /**
     * 根据订单号查询司机坐标
     * @param orderNo
     * @return
     */
    @Override
    public List<DriverPoint> selectByOrderNo(String orderNo) {
        return driverPointMapper.selectByOrderNo(orderNo);
    }

    /**
     * 司机坐标保存到HBase
     * @param driverPointDto
     * @return
     */
    @Override
    public Object driverLocationToHBase(DriverPointDto driverPointDto) {
        // 将driverPointDto属性值拷贝给DriverPoint
        DriverPoint driverPoint = BeanUtil.copyProperties(driverPointDto, DriverPoint.class);
        // 生成雪花id
        driverPoint.setId(IdUtil.getSnowflake().nextId());
        // 设置司机编号
        driverPoint.setDriverId(StpUtil.getLoginIdAsLong());
        // 司机坐标保存到HBase
        driverPointMapper.save(driverPoint);
        return true;
    }
}
